class CouponModel {
  int code = 0;
  String msg = '';
  List<CouponListModel> data = [];

  CouponModel();

  CouponModel.fromJson(Map<String, dynamic> json) {
    code = json['code'] ?? 0;
    msg = json['msg'] ?? '';
    if (json['data'] != null) {
      data = List<CouponListModel>.from(
        (json['data'] as List).map((e) => CouponListModel.fromJson(e)),
      );
    }
  }
}

class CouponListModel {
  double cill = 0;
  String name = '';
  String effectiveTime = '';
  String infor = '';
  String createTime = '';
  double parvalue = 0;
  String description = '';
  int spuCouponsId = 0;
  String scope = '';
  String symbol = '';
  String type = '';
  int status = 0;
  double max = 0;

  CouponListModel();

  CouponListModel copyWith({
    double? cill,
    String? name,
    String? effectiveTime,
    String? infor,
    String? createTime,
    double? parvalue,
    String? description,
    int? spuCouponsId,
    String? scope,
    String? symbol,
    String? type,
    int? status,
    double? max,
  }) {
    return CouponListModel()
      ..cill = cill ?? this.cill
      ..name = name ?? this.name
      ..effectiveTime = effectiveTime ?? this.effectiveTime
      ..infor = infor ?? this.infor
      ..createTime = createTime ?? this.createTime
      ..parvalue = parvalue ?? this.parvalue
      ..description = description ?? this.description
      ..spuCouponsId = spuCouponsId ?? this.spuCouponsId
      ..scope = scope ?? this.scope
      ..symbol = symbol ?? this.symbol
      ..type = type ?? this.type
      ..status = status ?? this.status
      ..max = max ?? this.max;
  }

  CouponListModel.fromJson(Map<String, dynamic> json) {
    cill = (json['cill'] ?? 0).toDouble();
    name = json['name'] ?? '';
    effectiveTime = json['effectiveTime'] ?? '';
    infor = json['infor'] ?? '';
    createTime = json['createTime'] ?? '';
    parvalue = (json['parvalue'] ?? 0).toDouble();
    description = json['description'] ?? '';
    spuCouponsId = json['spuCouponsId'] ?? 0;
    scope = json['scope'] ?? '';
    symbol = json['symbol'] ?? '';
    type = json['type'] ?? '';
    status = json['status'] ?? 0;
    max = (json['max'] ?? 0).toDouble();
  }
}

class CouponDeModel {
  int code = 0;
  String msg = '';
  List<CouponDeListModel> data = [];

  CouponDeModel();

  factory CouponDeModel.fromJson(Map<String, dynamic> json) {
    var model = CouponDeModel();
    model.code = json['code'] ?? 0;
    model.msg = json['msg'] ?? '';

    // data 可能是 list 也可能是 0
    var rawData = json['data'];
    if (rawData is List) {
      model.data = rawData.map((e) => CouponDeListModel.fromJson(e)).toList();
    } else {
      model.data = []; // 如果是 0 或其他类型，就置为空数组
    }

    return model;
  }
}

class CouponDeListModel {
  double cill = 0;
  String spuName = '';
  int days = 0;
  String infor = '';
  String createTime = '';
  double parvalue = 0;
  String description = '';
  int spuCouponsId = 0;
  double receiveStatus = 0;
  double id = 0;
  double status = 0;
  String symbol = '';
  String type = '';
  double max = 0;

  CouponDeListModel();

  factory CouponDeListModel.fromJson(Map<String, dynamic> json) {
    return CouponDeListModel()
      ..cill = (json['cill'] ?? 0).toDouble()
      ..spuName = json['spuName'] ?? ''
      ..days = json['days'] ?? 0
      ..infor = json['infor'] ?? ''
      ..createTime = json['createTime'] ?? ''
      ..parvalue = (json['parvalue'] ?? 0).toDouble()
      ..description = json['description'] ?? ''
      ..spuCouponsId = json['spuCouponsId'] ?? 0
      ..receiveStatus = (json['receiveStatus'] ?? 0).toDouble()
      ..id = (json['id'] ?? 0).toDouble()
      ..status = (json['status'] ?? 0).toDouble()
      ..symbol = json['symbol'] ?? ''
      ..type = json['type'] ?? ''
      ..max = (json['max'] ?? 0).toDouble();
  }

  Map<String, dynamic> toJson() {
    return {
      'cill': cill,
      'spuName': spuName,
      'days': days,
      'infor': infor,
      'createTime': createTime,
      'parvalue': parvalue,
      'description': description,
      'spuCouponsId': spuCouponsId,
      'receiveStatus': receiveStatus,
      'id': id,
      'status': status,
      'symbol': symbol,
      'type': type,
      'max': max,
    };
  }
}

class VoucherCodeModel {
  int code;
  String msg;
  VoucherCodeInfo? data;

  VoucherCodeModel({
    this.code = 0,
    this.msg = '',
    this.data,
  });

  factory VoucherCodeModel.fromJson(Map<String, dynamic> json) {
    return VoucherCodeModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? VoucherCodeInfo.fromJson(json['data']) : null,
    );
  }
}

class VoucherCodeInfo {
  int userSpuCouponsId;

  VoucherCodeInfo({
    this.userSpuCouponsId = 0,
  });

  factory VoucherCodeInfo.fromJson(Map<String, dynamic> json) {
    return VoucherCodeInfo(
      userSpuCouponsId: json['userSpuCouponsId'] ?? 0,
    );
  }
}



